﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Toon.Controls;
using Toon.Models.Catalogs;
using Toon.Models.Characters;
using System.Windows.Controls;

namespace Toon.Dialogs
{
	public partial class PossessionPicker : ImprovedChildWindow
	{
		public PossessionPicker()
		{
			this.AddConverter<PossessionType, bool>("UnusualCheckBox",
				v => v != PossessionType.Normal,
				b => b ? PossessionType.Unusual : PossessionType.Normal);
			this.AddConverter<PossessionType, bool>("UnusualCheckBoxIsEnabled", v => v != PossessionType.Gizmo);

			this.AddCommand<PossessionDefinition>("AddPossession", v => TypedDataContext.Possessions.Add(v));
			this.AddCommand<PossessionDefinition>("NewPossession", v => TypedDataContext.Possessions.AddNew());
			this.AddCommand<Possession>("RemovePossession", v => TypedDataContext.Possessions.Remove(v));
			this.AddCommand<IChoosable<PossessionDefinition>>("RandomPick", v => TypedDataContext.Possessions.Add(v.ChooseOne()));
			this.AddCommand<IChoosable<PossessionDefinition>>("RandomPickAll", v => TypedDataContext.Rules.AddRandomPossessions(TypedDataContext));

			InitializeComponent();
		}

		public Character TypedDataContext
		{
			get { return (Character)DataContext; }
		}


		public static PossessionPicker Show(Control owner, Character character)
		{
			var dlg = new PossessionPicker();
			dlg.DataContext = character;
			dlg.Show(owner);

			return dlg;
		}

		private void OKButton_Click(object sender, RoutedEventArgs e)
		{
			DialogResult = true;
		}

	}
}

